from django.shortcuts import render
from django.http import HttpResponse

from django.http import JsonResponse

from django.views.generic import View

import json

# Create your views here.


def index(request):
    return HttpResponse('Hello, beautiful django!!')


# 在定义message函数时，request类未知，ide无法预知
# GET对象
def message(request):
    name = request.GET.get('name')
    age = request.GET.get('age',10)

    print(name)
    print(age)
    # json操作
    return HttpResponse(json.dump(name))


def page(request,year):

    print(year)
    print(dir(request))

    return  HttpResponse(year)


# 继承
class BookService(View):

    def index(self, request):
        print(request)
        name = request.GET.get('name1','2222')
        ret = {'name1',name}
        return HttpResponse("dddd")

    #  父类方法，就可以不传参数？
    def as_view(self, request):
        print(request)
        name = request.GET.get('name1', '2222')
        # set  = {set1,set2},
        ret = {'name1': name}
        return JsonResponse(ret)


    def view_pagee(self,request):

        name = request.GET.get("name",'liyong')
        #  render
        return  render(request,'index.html',{'name':name})

